
const POLYPATH = (width, height) => [
  {
    key: 'side3',
    side: 3,
    label: '三角形',
    path: pathStr([
      0, height / 2 + height / (2 * Math.tan(Math.PI / 3)),
      width / 2, 0,
      width, height / 2 + height / (2 * Math.tan(Math.PI / 3)),
    ]),
  },
  {
    key: 'side4',
    side: 4,
    label: '四边形',
    path: pathStr([
      0, 0, width, 0,
      width, height, 0, height,
    ]),
  },
  {
    key: 'side5',
    side: 5,
    label: '五边形',
    path: pathStr([
      (width / 2) * (1 - Math.sin( Math.PI / 5)), (height / 2) * (1 + Math.cos( Math.PI / 5)),
      (width / 2) * (1 - Math.cos( Math.PI / 10)), (height / 2) * (1 - Math.sin( Math.PI / 10)),
      width / 2, 0,
      (width / 2) * (1 + Math.cos( Math.PI / 10)), (height / 2) * (1 - Math.sin( Math.PI / 10)),
      (width / 2) * (1 + Math.sin( Math.PI / 5)), (height / 2) * (1 + Math.cos( Math.PI / 5)),
    ]),
  },
  {
    key: 'side6',
    side: 6,
    label: '六边形',
    path: pathStr([
      (width / 2) * (1 - Math.sin( Math.PI / 6)), (height / 2) * (1 + Math.cos( Math.PI / 6)),
      0, height / 2,
      (width / 2) * (1 - Math.sin( Math.PI / 6)), (height / 2) * (1 - Math.cos( Math.PI / 6)),
      (width / 2) * (1 + Math.sin( Math.PI / 6)), (height / 2) * (1 - Math.cos( Math.PI / 6)),
      width, height / 2,
      (width / 2) * (1 + Math.sin( Math.PI / 6)), (height / 2) * (1 + Math.cos( Math.PI / 6)),
    ]),
  },
  {
    key: 'side7',
    side: 7,
    label: '七边形',
    path: pathStr([
      (width / 2) * (1 - Math.sin( Math.PI / 7)), (height / 2) * (1 + Math.cos( Math.PI / 7)),
      (width / 2) * (1 - Math.sin( Math.PI * 3 / 7)), (height / 2) * (1 + Math.cos( Math.PI * 3 / 7)),
      (width / 2) * (1 - Math.sin( Math.PI * 2 / 7)), (height / 2) * (1 - Math.cos( Math.PI * 2 / 7)),
      width / 2, 0,
      (width / 2) * (1 + Math.sin( Math.PI * 2 / 7)), (height / 2) * (1 - Math.cos( Math.PI * 2 / 7)),
      (width / 2) * (1 + Math.sin( Math.PI * 3 / 7)), (height / 2) * (1 + Math.cos( Math.PI * 3 / 7)),
      (width / 2) * (1 + Math.sin( Math.PI / 7)), (height / 2) * (1 + Math.cos( Math.PI / 7)),
    ]),
  },
  {
    key: 'side8',
    side: 8,
    label: '八边形',
    path: pathStr([
      (width / 2) * (1 - Math.sin( Math.PI / 4)), (height / 2) * (1 + Math.cos( Math.PI / 4)),
      0, height / 2,
      (width / 2) * (1 - Math.sin( Math.PI / 4)), (height / 2) * (1 - Math.cos( Math.PI / 4)),
      width / 2, 0,
      (width / 2) * (1 + Math.sin( Math.PI / 4)), (height / 2) * (1 - Math.cos( Math.PI / 4)),
      width, height / 2,
      (width / 2) * (1 + Math.sin( Math.PI / 4)), (height / 2) * (1 + Math.cos( Math.PI / 4)),
      width / 2, height,
    ]),
  },
  {
    key: 'side9',
    side: 9,
    label: '九边型',
    path: pathStr([
      (width / 2) * (1 - Math.sin( Math.PI / 9)), (height / 2) * (1 + Math.cos( Math.PI / 9)),
      (width / 2) * (1 - Math.sin( Math.PI * 3 / 9)), (height / 2) * (1 + Math.cos( Math.PI * 3 / 9)),
      (width / 2) * (1 - Math.sin( Math.PI * 4 / 9)), (height / 2) * (1 - Math.cos( Math.PI * 4 / 9)),
      (width / 2) * (1 - Math.sin( Math.PI * 2 / 9)), (height / 2) * (1 - Math.cos( Math.PI * 2 / 9)),
      width / 2, 0,
      (width / 2) * (1 + Math.sin( Math.PI * 2 / 9)), (height / 2) * (1 - Math.cos( Math.PI * 2 / 9)),
      (width / 2) * (1 + Math.sin( Math.PI * 4 / 9)), (height / 2) * (1 - Math.cos( Math.PI * 4 / 9)),
      (width / 2) * (1 + Math.sin( Math.PI * 3 / 9)), (height / 2) * (1 + Math.cos( Math.PI * 3 / 9)),
      (width / 2) * (1 + Math.sin( Math.PI / 9)), (height / 2) * (1 + Math.cos( Math.PI / 9)),
    ]),
  },
  {
    key: 'side10',
    side: 10,
    label: '十边形',
    path: pathStr([
      (width / 2) * (1 - Math.sin( Math.PI / 5)), (height / 2) * (1 + Math.cos( Math.PI / 5)),
      (width / 2) * (1 - Math.sin( Math.PI * 2 / 5)), (height / 2) * (1 + Math.cos( Math.PI * 2 / 5)),
      (width / 2) * (1 - Math.sin( Math.PI * 2 / 5)), (height / 2) * (1 - Math.cos( Math.PI * 2 / 5)),
      (width / 2) * (1 - Math.sin( Math.PI / 5)), (height / 2) * (1 - Math.cos( Math.PI / 5)),
      width / 2, 0,
      (width / 2) * (1 + Math.sin( Math.PI / 5)), (height / 2) * (1 - Math.cos( Math.PI / 5)),
      (width / 2) * (1 + Math.sin( Math.PI * 2 / 5)), (height / 2) * (1 - Math.cos( Math.PI * 2 / 5)),
      (width / 2) * (1 + Math.sin( Math.PI * 2 / 5)), (height / 2) * (1 + Math.cos( Math.PI * 2 / 5)),
      (width / 2) * (1 + Math.sin( Math.PI / 5)), (height / 2) * (1 + Math.cos( Math.PI / 5)),
      width / 2, height,
    ]),
  }
];

const pathStr = arr => {
  let dd = '';
  arr.forEach((item, index) => {
    if (index === 0) {
      dd += `M ${item} `;
    } else if (index !== 0 && index % 2 === 0) {
      dd += `L ${item} `;
    } else {
      dd += `${item} `;
    }
  });
  return `${dd} Z`;
};

export default POLYPATH;
